class Solution {
public:
    void reverse(vector<int>& nums, int left, int right)
    {
        while (left < right)
        {
            int tmp = nums[left];
            nums[left] = nums[right];
            nums[right] = tmp;
            ++left;
            --right;
        }
    }
    void rotate(vector<int>& nums, int k) {
        int n = k % nums.size();
        if (0 == n)
            return;
        reverse(nums, 0, nums.size() - 1);
        reverse(nums, 0, n - 1);
        reverse(nums, n, nums.size() - 1);
        return;
    }
};